<%@ page pageEncoding="UTF-8" %>
<%@ include file="/common/validate.jsp" %>
<%@ include file="../function.jsp" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>医生信息</title>
    <link href="/images/favicon.ico?cache=<%=Math.random()%>" rel="shortcut icon" type="image/x-icon">
    <link rel="stylesheet" href="/css/public.css?cache=<%=Math.random()%>">
    <link rel="stylesheet" href="/css/messages_doctor_mes.css?cache=<%=Math.random()%>">
    <link rel="stylesheet" href="/css/sweetalert.css?cache=<%=Math.random()%>" >
    <link rel="stylesheet" href="/css/pageCode.css?cache=<%=Math.random()%>" />
    <script src="/js/jquery-1.9.1.min.js"></script>
</head>
<body>
<%@ include file="/header.jsp" %>
<!--内容-->
<div class="containerone">
    <%@ include file="/left_menu.jsp" %>
    <!--右边内容-->
    <div class="right_cont">
        <div id="web">
            <doctor></doctor>
        </div>
        <!--右边导航下面内容-->
        <div class="message_right_cont_box">
            <script type="x-template" id="doctor">
                <div class="message_right_cont_container" >

                    <%--根据科室选医生--%>
                    <!--左边的渠道-->
                    <div class="department_top">
                        <div  v-if="choose">
                            <div class="department_top_left">
        <span>
        <p class="padding-right-min">选择科室:</p>
        <select class="doc_edi_sel par_choose_select" id="select_one" @change="choose_first_depts()">
        <option value="-1" >全部</option>
        <template v-for="first_dept in first_depts">
        <option :value="first_dept.id"  :deptCode="first_dept.deptCode"  v-html="first_dept.deptName"></option>
        </template>

        </select>
        </span>
                                <span class="margin-left">
        <select class="doc_edi_sel ch_choose_select" id="select_two" @change="choose_second_depts()">
        <option value="-1">全部</option>
        <template v-for="second_dept in second_depts">
        <option :value="second_dept.id"   v-html="second_dept.deptName"></option>
        </template>
        </select>
        </span>

                            </div>
                            <!--右边的搜索\添加\批量添加-->
                            <div class="department_top_right">
                                <span class="search_btn" @click="search_a()">搜索</span>
                                <%
                                    if (checkAuth("增加医生", input)) {
                                %>
                                <span class="add_btn
        doctor_add_btn" @click="add_doctor()">添加</span>
                                <%
                                    }
                                %>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                        <%--搜索--%>
                        <div class="department_search" v-if="search">
                            <span class="cho_depar"  @click="choose_a()">选择科室</span>
                            <span class="search_input">
        <input type="text" placeholder="请输入医生编号或姓名" class="search_doctor_name">
        <span class="sure_search" @click="search_doctor()">确定</span>
        </span>
                        </div>
                    </div>
                    <!--序号/姓名/科室名称/级别/类型/医生编号/操作-->
                    <div class="department_detail" id="doctor_detail">
                        <input type='hidden' id='current_page' />
                        <input type='hidden' id='show_per_page' />
                        <table >
                            <tr class='department_detail_tittle'>
                                <th class='ui_widthone'>头像</th>
                                <th class='ui_widthone'>医生编号</th>
                                <th class='ui_widthone'>姓名</th>
                                <th class='ui_widththree'>所属科室</th>
                                <th class='ui_widthone'>级别</th>
                                <th class='ui_widthtwo'>操作</th>
                            </tr>
                            <tbody id="content">

                            <template v-for="list_doctor in doctor.rank">
                                <tr class="department_detail_c" >
                                    <td class="ui_doctor_head ui_widthone"><img :src="list_doctor.head_image"></td>
                                    <td class='ui_widthone' v-html="limitnumber(list_doctor.expertId)"></td>
                                    <td class='ui_widthone' v-html="limitnumber(list_doctor.name)"></td>
                                    <td class='ui_widththree' v-html="list_doctor.deptName">
                                    </td>
                                    <td class='ui_widthone' v-html="list_doctor.level"></td>
                                    <td class='ui_color ui_widthtwo ui_padding'>
                                        <%
                                            if (checkAuth("查看医生详情", input)) {
                                        %>
                                        <span class="mes_doc_edit doctor_add_btn " @click="see_doctor(list_doctor.id)"><a >查看</a></span>
                                        <%
                                            }
                                        %>
                                        <%
                                            if (checkAuth("编辑医生", input)) {
                                        %>
                                        <span class="mes_doc_edit doctor_add_btn " @click="edit_doctor(list_doctor.id)"><a >编辑</a></span>
                                        <%
                                            }
                                        %>
                                        <%
                                            if (checkAuth("删除医生", input)) {
                                        %>
                                        <span class="delete_doc_mes " @click="delete_doctor(list_doctor.expertId)">删除</span>
                                        <%
                                            }
                                        %>
                                    </td>
                                </tr>
                            </template>

                            </tbody>
                        </table>
                        <%--显示页码--%>
                        <div class="split_pages">
                            <div class="record">共<span class="ui_red" v-html="doctor.count"></span>记录</div>
                            <div class="tcdPageCode holder"></div>
                        </div>
                    </div>

                </div>
            </script>
        </div>
    </div>
</div>
<script src="/js/sweetalert-dev.js"></script>
<script src="/js/jquery.page.js"></script>
<script>
    var doctor = {
        template:"#doctor",
        data:function(){
            return{
                choose:true,
                search:false,
                first_deptid:"",
                second_deptid:"",
                first_deptcode:"",
                keywords:"",
                first_depts:[],
                second_depts:[],
                doctor:[]
            }
        },
        methods:{
            search_a:function(){
                var self=this;
                self.choose = false;
                self.search = true;
                self.first_deptid = "";
                self.second_deptid = "";
                self.first_deptcode = "";
            },
            choose_a:function(){
                var self = this;
                self.choose = true;
                self.search = false;
                self.first_deptcode = $('.par_choose_select option:selected').attr('deptCode');
                self.first_deptid = $('.par_choose_select option:selected').val();
                self.second_deptid = $('.ch_choose_select option:selected').val();
                self.keywords = "";
                self.get_doctors();
            },
            <%--获取一级科室列表--%>
            get_first_depts:function(){
                var self=this;
                $.ajax({
                    type: 'post',
                    url: "see.jsp",
                    data: {
                        act:"first_depts",
                    },
                    timeout: 3000,
                    dataType: 'json',
                    success:function (res) {
                        if(res.errcode==0){
                            console.log(res)
                            self.first_depts=res.depts;
                        }else{
                            swal('没有一级科室列表数据')
                        }
                        //console.log(data)
                    },
                    error:function (error) {
                        swal('没有一级科室列表数据')
                    }
                });
            },
            <%--获取二级科室列表--%>
            get_second_depts:function(){
                var self=this;
                $.ajax({
                    type: 'post',
                    url: "see.jsp",
                    data: {
                        act:"second_depts",
                        deptCode:self.first_deptcode
                    },
                    timeout: 3000,
                    dataType: 'json',
                    success:function (res) {
                        if(res.errcode==0){
                            self.second_depts=res.depts;
                        }else{
                            swal('没有一级科室列表数据')
                        }
                        //console.log(data)
                    },
                    error:function (error) {
                        swal('没有一级科室列表数据')
                    }
                });
            },
            <%--获取医生列表--%>
            get_doctors:function(){
                var self=this;
                <%--拿到医生初始列表--%>
                $.ajax({
                    type: 'post',
                    url: "see.jsp",
                    data: {
                        act:"doctors",
                        first_id:self.first_deptid ,
                        second_id:self.second_deptid ,
                        keywords:self.keywords,
                    },
                    timeout: 3000,
                    dataType: 'json',
                    success:function (res) {
                        if(res.errcode==0){
                            self.doctor=res.data;
                            $(".tcdPageCode")[0].outerHTML = $(".tcdPageCode")[0].outerHTML;
                            <%--初始分页--%>
                            $(".tcdPageCode").createPage({
                                pageCount: self.doctor.page_count,
                                current:self.doctor.current_page,
                                backFn:function(p){
                                    $.ajax({
                                        type: 'post',
                                        url: "see.jsp",
                                        async: false,
                                        data: {
                                            act:"doctors",
                                            first_id:self.first_deptid,
                                            second_id:self.second_deptid,
                                            page:p
                                        },
                                        timeout: 3000,
                                        dataType: 'json',
                                        success: function(res) {
                                            if (res.errcode == 0) {
                                                self.doctor = res.data;
                                            }
                                        },
                                        error: function(error) {
                                        }
                                    });
                                    return false;//阻止提交
                                }
                            });
                        }else{
                            console.log(res);
                            self.doctor=[];
                            $(".tcdPageCode")[0].outerHTML = $(".tcdPageCode")[0].outerHTML;
                            $(".tcdPageCode").createPage({
                                pageCount:0,
                                current:0})
                            swal('没有相关一级科室列表数据')
                        }
                        //console.log(data)
                    },
                    error:function (error) {
                        swal('没有一级科室列表数据')
                    }
                });
            },
            choose_first_depts:function(){
                var self=this;
                self.first_deptcode = $('.par_choose_select option:selected').attr('deptCode');
                self.first_deptid = $('.par_choose_select option:selected').val();
                self.second_deptid = "";
                self.get_second_depts()
                self.get_doctors();
            },
            choose_second_depts:function(){
                var self=this;
                self.first_deptcode = $('.par_choose_select option:selected').attr('deptCode');
                self.first_deptid = $('.par_choose_select option:selected').val();
                self.second_deptid = $('.ch_choose_select option:selected').val();
                self.get_doctors();
            },
            <%--删除医生--%>
            delete_doctor:function(doctorCode){
                swal({
                        title: "您确定要删除吗？",
                        type: "warning",
                        showCancelButton: true,
                        closeOnConfirm: false,
                        confirmButtonText: "是的，我要删除",
                        cancelButtonText:"取消",
                        confirmButtonColor: "#ec6c62"
                    },
                    function(){
                        $.ajax({
                            type: 'post',
                            url: "see.jsp",
                            data: {
                                act:'delete_doctor',
                                doctorCode:doctorCode,
                            },
                            timeout: 3000,
                            dataType: 'json',
                            success:function (data) {
                                console.log(data);
                                if(data.errcode==0){
                                    swal({
                                        title:"删除成功"
                                    },function(){
                                        self.location.reload()
                                    })
                                }else{
                                    swal('删除失败')
                                }

                                //console.log(data)
                            },
                            error:function (error) {
                                swal('删除失败')
                            }
                        });
                        return false;//阻止提交
                    }

                );
            },
            limitnumber:function(txt) {
                if(txt.length>20){
                    txt = txt.substr(0,20) + '......' ;
                    return txt;
                }
                else{
                    return txt;
                }
            },
            search_doctor:function(){
                var self=this;
                self.keywords=$('.search_doctor_name').val().trim();
                self.get_doctors();
            },
            add_doctor:function(){
                locationHerf("add_doctor")
            },
            see_doctor: function(item) {
                locationHerf("see_doctor", {
                    id:item
                });
            },
            edit_doctor:function(item){
                locationHerf("edit_doctor", {
                    id:item
                });}
        },
        ready:function(){
            var self=this;
            self.get_first_depts();
            self.get_doctors()
        },
    }
    new Vue({
        el: "#web",
        components: {
            doctor: doctor
        }
    });
</script>
</body>
</html>
